<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://unpkg.com/vue@3"></script>
</head>
<body>
    <div id="app">
        <h1>知识点1：迭代普通数组</h1>
            <ul>
                <li v-for="item in times">桃花</li>
            </ul>
            <ul>
                <li v-for="item in flowers">{{item}}</li>
            </ul>
            <ul>
                <li v-for="(item,index) in flowers">{{index}}--{{item}}</li>
            </ul>
        <h1>知识点2.迭代对象数组</h1>
            <ul>
                <li v-for="(item,index) in users">{{item.name}}</li>
            </ul>
        <h1>知识点3.迭代数字</h1>
            <ul>
                <li v-for="list in 10">{{list}}</li>
            </ul>
        <h1>知识点4.关于key属性</h1>
            <div>
                <table border="1" >
                    <tr>
                        <td>ID:</td>
                        <td><input type="text" v-model="id"></td>
                    </tr>
                    <tr>
                        <td>Name:</td>
                        <td><input type="text" v-model="name"></td>
                    </tr>
                    <tr>
                        <td colspan="2"><button>添加</button>
                            <button>删除</button></td>
                    </tr>
                </table>
                我新添加的id是{{id}}，我新添加的Name是{{name}}
            </div>

            <table border="1">
                <tr v-for="(item,index) in users" :key="item.index">
                    <td><input type="checkbox" ></td>
                    <td>{{item.id}}</td>
                    <td>{{item.name}}</td>
                </tr>
            </table>
            <h3>为了提升循环性能，我们一般会给每个循环加上一个唯一的key值，在实际中
            后端会向前端返回数据时，一般会携带唯一的与数据相关的数据条目标志符
            通常是一个随机字段，我们写v-for的时候，要加上key属性</h3>
        <h1>知识点5.v-for的嵌套</h1>
        <ul>
            <li v-for="(item,index) in users">用户{{index+1}}
                <div>
                    <p v-for="(list,i) in item">{{i}}:{{list}}</p>
                </div>
            </li>
        </ul>

    </div>
</body>
</html>

<script>
    const appConn = Vue.createApp({
        data() {
            return {
              times:5,
              flowers:['菊花','梅花','荷花','石楠花','木槿花'],
              users:[{id:'001',name:'老八'},{id:'002',name:'老六'}],
              id:'',
              name:'',

            }
        },
        methods: {
            add(){
                // this.users.push({id:this.id,name:this.name})
                this.users.unshift({id:this.id,name:this.name})
            },
            del(){
                //用shift在头部删除，用pop在尾部删除
                this.users.shift()
            }
        },
    }).mount('#app')
</script>